<?php

namespace App\Modules\Diagnose\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * Class Graphic 图文咨询
 * @package App\Modules\Task\Models
 */
class Graphic extends Model
{
    protected $table = 'diagnose';

    protected $fillable = ['id', 'user_id', 'doctor_id', 'group_id', 'initiator_identity', 'type', 'content', 'accessory', 'duration', 'created_at', 'updated_at', 'status','prescription'];

    static function getList($param)
    {
        return self::where('status','>',0)->paginate($param['size']);
    }

    static function get($user_id,$group_id)
    {
        return self::where('user_id',$user_id)->where('id',$group_id)->where('status','>',0)->first();
    }

    static function getDetails($user_id,$group_id,$size)
    {
        return self::from('diagnose AS D')->select(['D.id','D.user_id','D.doctor_id','D.group_id','D.initiator_identity','D.content','D.accessory','D.created_at','C.name','C.photo','C.position'])
                    ->leftJoin('doctor AS C','D.doctor_id','=','C.id')
                    ->where('D.user_id',$user_id)->where('type',2)
                    ->where('D.group_id',$group_id)
//                    ->where(function($query) use ($group_id) {
//                        $query->where('D.group_id',$group_id)->orWhere('D.id',$group_id);
//                    })
                    ->orderBy('D.created_at','ASC')
                    ->paginate($size);
    }

    static function add($param)
    {
        // TODO check
        return self::create($param);
    }

    static function updateSave($param)
    {
        return self::where('id',$param['id'])->update($param);
    }
}